package customer

import (
	"counter-help/admin/server/global"
    "counter-help/admin/server/model/common/response"
    "counter-help/admin/server/model/customer"
    customerReq "counter-help/admin/server/model/customer/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type CusFeedbackApi struct {}

// CreateCusFeedback 创建cusFeedback表
// @Tags CusFeedback
// @Summary 创建cusFeedback表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body customer.CusFeedback true "创建cusFeedback表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /cusFeedback/createCusFeedback [post]
func (cusFeedbackApi *CusFeedbackApi) CreateCusFeedback(c *gin.Context) {
	var cusFeedback customer.CusFeedback
	err := c.ShouldBindJSON(&cusFeedback)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = cusFeedbackService.CreateCusFeedback(&cusFeedback)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteCusFeedback 删除cusFeedback表
// @Tags CusFeedback
// @Summary 删除cusFeedback表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body customer.CusFeedback true "删除cusFeedback表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /cusFeedback/deleteCusFeedback [delete]
func (cusFeedbackApi *CusFeedbackApi) DeleteCusFeedback(c *gin.Context) {
	ID := c.Query("ID")
	err := cusFeedbackService.DeleteCusFeedback(ID)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteCusFeedbackByIds 批量删除cusFeedback表
// @Tags CusFeedback
// @Summary 批量删除cusFeedback表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /cusFeedback/deleteCusFeedbackByIds [delete]
func (cusFeedbackApi *CusFeedbackApi) DeleteCusFeedbackByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	err := cusFeedbackService.DeleteCusFeedbackByIds(IDs)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateCusFeedback 更新cusFeedback表
// @Tags CusFeedback
// @Summary 更新cusFeedback表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body customer.CusFeedback true "更新cusFeedback表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /cusFeedback/updateCusFeedback [put]
func (cusFeedbackApi *CusFeedbackApi) UpdateCusFeedback(c *gin.Context) {
	var cusFeedback customer.CusFeedback
	err := c.ShouldBindJSON(&cusFeedback)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = cusFeedbackService.UpdateCusFeedback(cusFeedback)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindCusFeedback 用id查询cusFeedback表
// @Tags CusFeedback
// @Summary 用id查询cusFeedback表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query customer.CusFeedback true "用id查询cusFeedback表"
// @Success 200 {object} response.Response{data=customer.CusFeedback,msg=string} "查询成功"
// @Router /cusFeedback/findCusFeedback [get]
func (cusFeedbackApi *CusFeedbackApi) FindCusFeedback(c *gin.Context) {
	ID := c.Query("ID")
	recusFeedback, err := cusFeedbackService.GetCusFeedback(ID)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(recusFeedback, c)
}

// GetCusFeedbackList 分页获取cusFeedback表列表
// @Tags CusFeedback
// @Summary 分页获取cusFeedback表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query customerReq.CusFeedbackSearch true "分页获取cusFeedback表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /cusFeedback/getCusFeedbackList [get]
func (cusFeedbackApi *CusFeedbackApi) GetCusFeedbackList(c *gin.Context) {
	var pageInfo customerReq.CusFeedbackSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := cusFeedbackService.GetCusFeedbackInfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetCusFeedbackPublic 不需要鉴权的cusFeedback表接口
// @Tags CusFeedback
// @Summary 不需要鉴权的cusFeedback表接口
// @accept application/json
// @Produce application/json
// @Param data query customerReq.CusFeedbackSearch true "分页获取cusFeedback表列表"
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /cusFeedback/getCusFeedbackPublic [get]
func (cusFeedbackApi *CusFeedbackApi) GetCusFeedbackPublic(c *gin.Context) {
    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的cusFeedback表接口信息",
    }, "获取成功", c)
}
